package com.magicsoft.share.ui.my;

import android.content.Intent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.magicsoft.share.R;
import com.magicsoft.share.base.BaseActivity;
import com.magicsoft.share.bean.my.MessageRead;
import com.magicsoft.share.constant.Constant;
import com.magicsoft.share.presenter.my.MessagePresenter;
import com.magicsoft.share.view.my.IMessageView;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class MessageActivity extends BaseActivity<IMessageView, MessagePresenter> implements IMessageView {


    @BindView(R.id.view_top)
    View viewTop;
    @BindView(R.id.ibtn_left)
    ImageButton ibtnLeft;
    @BindView(R.id.tv_left)
    TextView tvLeft;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.ibtn_right)
    ImageButton ibtnRight;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.tv_notice)
    TextView tvNotice;
    @BindView(R.id.view_notice)
    View viewNotice;
    @BindView(R.id.layout_notice)
    RelativeLayout layoutNotice;
    @BindView(R.id.tv_interaction)
    TextView tvInteraction;
    @BindView(R.id.view_interaction)
    View viewInteraction;
    @BindView(R.id.layout_interaction)
    RelativeLayout layoutInteraction;
    @BindView(R.id.tv_follow)
    TextView tvFollow;
    @BindView(R.id.view_follow)
    View viewFollow;
    @BindView(R.id.layout_follow)
    RelativeLayout layoutFollow;
    @BindView(R.id.tv_like)
    TextView tvLike;
    @BindView(R.id.view_like)
    View viewLike;
    @BindView(R.id.layout_like)
    RelativeLayout layoutLike;
    @BindView(R.id.tv_collection)
    TextView tvCollection;
    @BindView(R.id.view_collection)
    View viewCollection;
    @BindView(R.id.layout_collection)
    RelativeLayout layoutCollection;
    @BindView(R.id.tv_comment)
    TextView tvComment;
    @BindView(R.id.view_comment)
    View viewComment;
    @BindView(R.id.layout_comment)
    RelativeLayout layoutComment;
    private int mResultCode;

    @Override
    public MessagePresenter initPresenter() {
        return new MessagePresenter();
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_message;
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {
        tvTitle.setText("我的消息");

    }

    @Override
    public void requestData() {

        mPresenter.messageRead();
    }


    @OnClick({R.id.ibtn_left, R.id.layout_notice, R.id.layout_interaction, R.id.layout_follow, R.id.layout_like, R.id.layout_collection, R.id.layout_comment})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ibtn_left:
                finish();
                break;
            case R.id.layout_notice:
                startActivityForResult(new Intent(this, NoticeActivity.class), Constant.REFRESH_UI);
                break;
            case R.id.layout_interaction:
                startActivityForResult(new Intent(this, InteractionActivity.class), Constant.REFRESH_UI);

                break;
            case R.id.layout_follow:
                startActivityForResult(new Intent(this, FollowMsgActivity.class), Constant.REFRESH_UI);

                break;
            case R.id.layout_like:
                startActivityForResult(new Intent(this, LikeActivity.class), Constant.REFRESH_UI);

                break;
            case R.id.layout_collection:
                startActivityForResult(new Intent(this, CollectionActivity.class), Constant.REFRESH_UI);

                break;
            case R.id.layout_comment:
                startActivityForResult(new Intent(this, CommentActivity.class), Constant.REFRESH_UI);
                break;
            default:
                break;
        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (resultCode == RESULT_OK) {

            if (requestCode == Constant.REFRESH_UI) {
                requestData();
                mResultCode = RESULT_OK;
            }
        }

    }

    @Override
    protected void onRestart() {
        super.onRestart();
        setResult(mResultCode);
    }

    @Override
    public void messageRead(MessageRead data) {
        List<MessageRead.ListBean> list = data.getList();
        for (MessageRead.ListBean bean : list) {
            //是否有未读消息(1:是；0：否)
            // 	消息类型（1：通知；2：互动；3：关注；4：点赞；5：收藏；6：评论
            int message_type = bean.getMessage_type();
            int read_type = bean.getRead_type();
            switch (message_type) {
                case 1:
                    if (read_type == 1) {
                        viewNotice.setVisibility(View.VISIBLE);
                    } else {
                        viewNotice.setVisibility(View.GONE);
                    }
                    break;
                case 2:
                    if (read_type == 1) {
                        viewInteraction.setVisibility(View.VISIBLE);
                    } else {
                        viewInteraction.setVisibility(View.GONE);
                    }
                    break;
                case 3:
                    if (read_type == 1) {
                        viewFollow.setVisibility(View.VISIBLE);
                    } else {
                        viewFollow.setVisibility(View.GONE);
                    }
                    break;
                case 4:
                    if (read_type == 1) {
                        viewLike.setVisibility(View.VISIBLE);
                    } else {
                        viewLike.setVisibility(View.GONE);
                    }
                    break;
                case 5:
                    if (read_type == 1) {
                        viewCollection.setVisibility(View.VISIBLE);
                    } else {
                        viewCollection.setVisibility(View.GONE);
                    }
                    break;
                case 6:
                    if (read_type == 1) {
                        viewComment.setVisibility(View.VISIBLE);
                    } else {
                        viewComment.setVisibility(View.GONE);
                    }
                    break;
                default:
                    break;
            }

        }


    }
}
